package com.travel.sight.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.travel.common.to.AttractionInfoTo;
import com.travel.sight.vo.AttractionVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.travel.sight.entity.AttractionInfoEntity;
import com.travel.sight.service.AttractionInfoService;
import com.travel.common.utils.PageUtils;
import com.travel.common.utils.R;



/**
 * 
 *
 * @author lxw
 * @email lxw@gmail.com
 * @date 2023-11-01 17:41:24
 */
@RestController
@RequestMapping("sight/attractioninfo")
public class AttractionInfoController {
    @Autowired
    AttractionInfoService attractionInfoService;

    /**
     * 获取所有的景点信息
     */
    @RequestMapping("/getAllAttraction")
    public List<AttractionInfoTo> getAllAttraction(){
        return attractionInfoService.getAllAttraction();
    }

    /**
     * 根据attractionid的集合获取AttractionInfoTo集合
     */
    @RequestMapping("/getAttractionsByIds")
    public List<AttractionInfoTo> getAttractionsByIds(@RequestParam("ids")List<Integer> ids){
        return attractionInfoService.getAttractionsByIds(ids);
    }

    /**
     * 根据标签名获取景点信息
     */
    @RequestMapping("/getAttractionByTagName/{tagName}")
    public List<AttractionInfoTo> getAttractionByTagName(@PathVariable("tagName")String tagName){
        return attractionInfoService.getAttractionByTagName(tagName);
    }


    /**
     * 获取用户的点赞、收藏、评论的总次数
     */
    @RequestMapping("/getBehaviorNum/{userId}")
    public Integer getBehaviorNum(@PathVariable("userId") Integer userId){
        return attractionInfoService.getBehaviorNum(userId);

    }



    /**
     * 列表
     */
    @RequestMapping("/list")
    //@RequiresPermissions("sight:attractioninfo:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = attractionInfoService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{attractionId}")
    //@RequiresPermissions("sight:attractioninfo:info")
    public R info(@PathVariable("attractionId") Integer attractionId){
		AttractionInfoEntity attractionInfo = attractionInfoService.getById(attractionId);

        return R.ok().put("attractionInfo", attractionInfo);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    //@RequiresPermissions("sight:attractioninfo:save")
    public R save(@RequestBody AttractionVo vo){
        //1. 将vo封装为attractionInfoEntity
        AttractionInfoEntity attractionInfoEntity = attractionInfoService.voToEntity(vo);
        //2. 保存到数据库
		attractionInfoService.save(attractionInfoEntity);
        //3. 保存到es中
        attractionInfoService.saveES(attractionInfoEntity);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    //@RequiresPermissions("sight:attractioninfo:update")
    public R update(@RequestBody AttractionInfoEntity attractionInfo){
		attractionInfoService.updateById(attractionInfo);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    //@RequiresPermissions("sight:attractioninfo:delete")
    public R delete(@RequestBody Integer[] attractionIds){
		attractionInfoService.removeByIds(Arrays.asList(attractionIds));

        return R.ok();
    }

}
